package com.ewanghuiju.app.ui.shopmail.activity;

import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.androidkun.xtablayout.XTabLayout;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.base.SimpleActivity;
import com.ewanghuiju.app.ui.main.adapter.MyPagerAdapter;
import com.ewanghuiju.app.ui.shopmail.fragment.LimitedSeckillFragment;
import com.ewanghuiju.app.widget.NoScrollViewPager;
import com.gyf.immersionbar.ImmersionBar;

import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.Fragment;
import butterknife.BindView;

/**
 * @author sj  qq:751943509
 * @class 限时秒杀页面
 * @time 2020/2/28
 */
public class LimitedSeckillActivity extends SimpleActivity {
    @BindView(R.id.top_bg)
    View topBg;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.toolbar)
    RelativeLayout toolbar;
    @BindView(R.id.xtabLayout)
    XTabLayout xtabLayout;
    @BindView(R.id.viewpage)
    NoScrollViewPager viewpage;

    private List<Fragment> fragmentList;
    private List<String> list_Title;

    LimitedSeckillFragment yhqFragment;//优惠券
    LimitedSeckillFragment waterFragment;//水滴

    @Override
    protected int getLayout() {
        return R.layout.activity_limited_seckill;
    }

    @Override
    protected void initEventAndData() {
        GradientDrawable aDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
                new int[]{Color.parseColor("#DA291C"), Color.parseColor("#FAFAFA")});
            topBg.setBackground(aDrawable);
        initFragment();
    }

    private void initFragment() {
//        xtabLayout.setSelectedTabIndicatorColor(R.mipmap.bg_splash);
        fragmentList = new ArrayList<>();
        list_Title = new ArrayList<>();
        list_Title.add("优惠券商品");
        list_Title.add("水滴抢购商品");
        yhqFragment = new LimitedSeckillFragment();
        waterFragment = new LimitedSeckillFragment();
        Bundle yhqBundle = new Bundle();
        yhqBundle.putInt(Constants.LIMITEDSECKILL_TYPE, Constants.LIMITEDSECKILL_TYPE_YHQ);
        yhqFragment.setArguments(yhqBundle);
        Bundle waterBundle = new Bundle();
        waterBundle.putInt(Constants.LIMITEDSECKILL_TYPE, Constants.LIMITEDSECKILL_TYPE_WATER);
        waterFragment.setArguments(waterBundle);
        fragmentList.add(yhqFragment);
        fragmentList.add(waterFragment);
        viewpage.setAdapter(new MyPagerAdapter(getSupportFragmentManager(), 0, fragmentList, list_Title));
        viewpage.setOffscreenPageLimit(2);
        xtabLayout.setupWithViewPager(viewpage);
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                .titleBar(toolbar, true)
                .init();
    }
}
